home *** CD-ROM | disk | FTP | other *** search
- class npb.NPBTracker extends MovieClip
- {
- var trackerVersion;
- var trackerVersiontxt;
- var eventCount;
- var npbso;
- var autohide;
- var productID;
- var clientID;
- var passkey;
- var instance;
- var status;
- var display;
- var machineID;
- var domain = this._url;
- var SCRIPT_PROTOCOL = "http://";
- var SCRIPT_DOMAIN = "www.npbmedia.com";
- var TEST_SCRIPT_DOMAIN = "devserver2";
- var SCRIPT_URL = npb.NPBTracker.prototype.SCRIPT_PROTOCOL + npb.NPBTracker.prototype.SCRIPT_DOMAIN + "/tracker/tracker_recorder.php";
- var TEST_SCRIPT_URL = npb.NPBTracker.prototype.SCRIPT_PROTOCOL + npb.NPBTracker.prototype.TEST_SCRIPT_DOMAIN + "/tracker_1_1/tracker_recorder.php";
- var isDev = false;
- var isDebug = true;
- var isValid = true;
- var isValidConnection = true;
- function NPBTracker()
- {
- super();
- this.trackerVersion = "1.2";
- this.trackerVersiontxt.text = this.trackerVersion;
- this.setStatus("NPB Tracker",true);
- this.eventCount = 0;
- AsBroadcaster.initialize(this);
- this.npbso = this.getSharedObject();
- System.security.allowDomain(this.SCRIPT_DOMAIN);
- _global.npbTracker = this;
- }
- function onLoad()
- {
- if(!this.init())
- {
- this.watch("productID",this.init);
- this.watch("clientID",this.init);
- this.watch("passkey",this.init);
- }
- else
- {
- if(this.autohide)
- {
- this._visible = false;
- }
- this.recordEvent("load");
- }
- }
- function getSharedObject()
- {
- return SharedObject.getLocal("NPBTracker" + this.productID,"/");
- }
- function init()
- {
- if(this.productID < 0)
- {
- this.setStatus("Error: Product ID not specified",true);
- return false;
- }
- if(this.clientID == -1)
- {
- this.setStatus("Error: ClientID not specified",true);
- return false;
- }
- if(this.passkey == "")
- {
- this.setStatus("Error: Passkey not specified",true);
- return false;
- }
- this.setStatus("Initialised",true);
- return true;
- }
- function onRelease()
- {
- if(this.isDebug)
- {
- this.recordEvent("Test Event");
- }
- }
- function recordEvent(eventName)
- {
- if(this.isDisabled())
- {
- this.setStatus("Error: This Tracker has been remotely disabled");
- return undefined;
- }
- if(!this.isValid)
- {
- this.setStatus("Error: Invalid clientid / password combination");
- return undefined;
- }
- if(!this.isValidConnection)
- {
- this.setStatus("Error: Connection unavailable");
- return undefined;
- }
- var me = this;
- var sendEvent = this.createEmptyMovieClip("sendEvent" + this.eventCount,this.eventCount);
- var e = sendEvent.createEmptyMovieClip("e",0);
- this.eventCount++;
- e.eventName = eventName;
- e.instance = this.instance;
- e.productID = this.productID;
- e.domain = this.domain;
- e.clientID = this.clientID;
- e.trackerversion = this.trackerVersion;
- e.passkey = this.passkey;
- e.machineid = this.getMachineID();
- sendEvent.onData = function()
- {
- var interval;
- var timeout = 0;
- trace("sendEvent.onData");
- interval = setInterval(function()
- {
- if(timeout++ < 100)
- {
- if(e.eventid || timeout++ > 100)
- {
- clearInterval(interval);
- trace("SendEvent::onData");
- me.setStatus("recieve:\'" + eventName + "\':" + e.eventid);
- me.setStatus("recieve:\'isvalid\':" + e.isvalid);
- me.setStatus("recieve:\'machineid\':" + e.machineid);
- if(me.machineID != Number(e.machineid))
- {
- me.setMachineID(e.machineid);
- }
- if(e.disableDate != undefined)
- {
- var dd = e.disableDate.split("|");
- var checkBack = new Date(dd[0],dd[1] - 1,dd[2],12,0,0);
- me.disable(checkBack);
- }
- me.isValid = e.isvalid;
- me.broadcastMessage("onData",sendEvent);
- }
- }
- else
- {
- this.isValidConnection = false;
- }
- }
- ,100);
- };
- if(this.isDev)
- {
- this.SCRIPT_URL = this.TEST_SCRIPT_URL;
- }
- trace("NPBTracker::recordEvent" + this.SCRIPT_URL);
- e.loadMovie(this.SCRIPT_URL,"POST");
- this.setStatus("send:\'" + eventName + "\':" + this.eventCount);
- }
- function setStatus(str, reset)
- {
- if(reset)
- {
- this.status = str + "\n";
- }
- else
- {
- this.status += str + "\n";
- }
- this.display.scroll = this.display.maxscroll;
- }
- function getMachineID()
- {
- this.machineID = this.npbso.data.machineID;
- if(this.machineID == "")
- {
- trace("no machine id set");
- this.machineID = -1;
- }
- return Number(this.machineID);
- }
- function setMachineID(id)
- {
- this.npbso.data.machineID = id;
- this.npbso.flush();
- }
- function isDisabled()
- {
- trace("Checking Enable");
- if(this.npbso.data.disabled != undefined)
- {
- var now = new Date();
- if(now.getTime() < this.npbso.data.disabled.getTime())
- {
- trace(this.npbso.data.disabled);
- return true;
- }
- trace("time elaspsed: " + this.npbso.data.disabled);
- this.enable();
- }
- return false;
- }
- function disable(d)
- {
- this.npbso.data.disabled = d;
- this.npbso.flush();
- trace("disabled");
- }
- function enable()
- {
- this.npbso.data.disabled = null;
- delete this.npbso.data.disabled;
- this.npbso.flush();
- delete this.npbso;
- this.npbso = this.getSharedObject();
- trace("enabled");
- }
- }
-